﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability.Adm;
using EntLibContrib.Query.Properties;

namespace EntLibContrib.Query.Configuration.Manageability.Parameters
{
	/// <summary>
	/// Provides an implementation for <see cref="CustomParameterData"/> that
	/// splits policy overrides processing and WMI objects generation, performing appropriate logging of 
	/// policy processing errors.
	/// </summary>
	public class CustomParameterDataManageabilityProvider
		: CustomProviderDataManageabilityProvider<CustomParameterData>
	{
		#region Construction
		/// <summary>
		/// Initialize a new instance of the <see cref="CustomParameterDataManageabilityProvider"/> class.
		/// </summary>
		public CustomParameterDataManageabilityProvider()
			: base(InternalResources.ParameterPolicyNameTemplate)
		{
			CustomParameterDataWmiMapper.RegisterWmiTypes();
		}
		#endregion

		#region Manageability Support
		/// <summary>
		/// Adds the ADM parts that represent the properties of
		/// a specific instance of the configuration element type managed by the receiver.
		/// </summary>
		/// <param name="contentBuilder">The <see cref="T:Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability.Adm.AdmContentBuilder"/> to which the Adm instructions are to be appended.</param>
		/// <param name="configurationObject">The configuration object instance.</param>
		/// <param name="configurationSource">The configuration source from where to get additional configuration
		/// information, if necessary.</param>
		/// <param name="elementPolicyKeyName">The key for the element's policies.</param>
		/// <remarks>
		/// Subclasses that manage custom provider's configuration objects with additional properties may
		/// override this method to add the corresponding parts.
		/// </remarks>
		/// <seealso cref="M:Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability.ConfigurationElementManageabilityProviderBase`1.AddAdministrativeTemplateDirectives(Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability.Adm.AdmContentBuilder,`0,Microsoft.Practices.EnterpriseLibrary.Common.Configuration.IConfigurationSource,System.String)"/>
		protected override void AddElementAdministrativeTemplateParts(AdmContentBuilder contentBuilder,
																																	CustomParameterData configurationObject,
																																	IConfigurationSource configurationSource,
																																	string elementPolicyKeyName)
		{
			base.AddElementAdministrativeTemplateParts(contentBuilder,
																								configurationObject,
																								configurationSource,
																								elementPolicyKeyName);
		}

		/// <summary>
		/// Creates the <see cref="ConfigurationSetting"/> instances that describe the 
		/// configurationObject.
		/// </summary>
		/// <param name="configurationObject">The configuration object for instances that must be managed.</param>
		/// <param name="wmiSettings">A collection to where the generated WMI objects are to be added.</param>
		protected override void GenerateWmiObjects(CustomParameterData configurationObject,
																							 ICollection<ConfigurationSetting> wmiSettings)
		{
			CustomParameterDataWmiMapper.GenerateWmiObjects(configurationObject, wmiSettings);
		}
		#endregion
	}
}
